mruby 4.0.0
mruby is the lightweight implementation of the Ruby language
Loading...
Searching...
No Matches
irep.h
Go to the documentation of this file.
1
6
7#ifndef MRUBY_IREP_H
8#define MRUBY_IREP_H
9
10#include "common.h"
11#include <mruby/compile.h>
12
17
19 IREP_TT_STR = 0, /* string (need free) */
20 IREP_TT_SSTR = 2, /* string (static) */
21 IREP_TT_INT32 = 1, /* 32-bit integer */
22 IREP_TT_INT64 = 3, /* 64-bit integer */
23 IREP_TT_BIGINT = 7, /* big integer */
24 IREP_TT_FLOAT = 5, /* float (double/float) */
25};
26
27#define IREP_TT_NFLAG 1 /* number (non string) flag */
28#define IREP_TT_SFLAG 2 /* static string flag */
29
30typedef struct mrb_irep_pool {
31 uint32_t tt; /* packed type and length (for string) */
32 union {
33 const char *str;
34 int32_t i32;
35 int64_t i64;
36#ifndef MRB_NO_FLOAT
37 mrb_float f;
38#endif
39 } u;
41
42enum mrb_catch_type {
43 MRB_CATCH_RESCUE = 0,
44 MRB_CATCH_ENSURE = 1,
45};
46
48 uint8_t type; /* enum mrb_catch_type */
49 uint8_t begin[4]; /* The starting address to match the handler. Includes this. */
50 uint8_t end[4]; /* The endpoint address that matches the handler. Not Includes this. */
51 uint8_t target[4]; /* The address to jump to if a match is made. */
52};
53
54/* Program data array struct */
55struct mrb_irep {
56 uint16_t nlocals; /* Number of local variables */
57 uint16_t nregs; /* Number of register variables */
58 uint16_t clen; /* Number of catch handlers */
59 uint8_t flags;
60
61 const mrb_code *iseq;
62 /*
63 * A catch handler table is placed after the iseq entity.
64 * The reason it doesn't add fields to the structure is to keep the mrb_irep
65 * structure from bloating. The catch handler table can be obtained with
66 * `mrb_irep_catch_handler_table(irep)`.
67 */
68 const mrb_irep_pool *pool;
69 const mrb_sym *syms;
70 const struct mrb_irep *const *reps;
71
72 const mrb_sym *lv;
73 /* debug info */
74 struct mrb_irep_debug_info *debug_info;
75
76 uint32_t ilen;
77 uint16_t plen, slen;
78 uint16_t rlen;
79 uint16_t refcnt;
80};
81
82#define MRB_ISEQ_NO_FREE 1
83#define MRB_IREP_NO_FREE 2
84#define MRB_IREP_STATIC (MRB_ISEQ_NO_FREE | MRB_IREP_NO_FREE)
85#define MRB_IREP_CONSOLIDATED 4 /* pool/syms/reps packed with irep struct */
86
87MRB_API mrb_irep *mrb_add_irep(mrb_state *mrb);
88
105
106/* @param [const uint8_t*] irep code, expected as a literal */
107MRB_API mrb_value mrb_load_irep(mrb_state *, const uint8_t *);
108
109/*
110 * @param [const void*] irep code
111 * @param [size_t] size of irep buffer.
112 */
113MRB_API mrb_value mrb_load_irep_buf(mrb_state *, const void *, size_t);
114
115/* @param [const uint8_t*] irep code, expected as a literal */
116MRB_API mrb_value mrb_load_irep_cxt(mrb_state *, const uint8_t *,
117 mrbc_context *);
118
119/*
120 * @param [const void*] irep code
121 * @param [size_t] size of irep buffer.
122 */
123MRB_API mrb_value mrb_load_irep_buf_cxt(mrb_state *, const void *, size_t,
124 mrbc_context *);
125
127 uint8_t insn;
128 uint32_t a;
129 uint16_t b;
130 uint16_t c;
131 const mrb_code *addr;
132};
133
134#define mrb_irep_catch_handler_pack(n, v) uint32_to_bin(n, v)
135#define mrb_irep_catch_handler_unpack(v) bin_to_uint32(v)
136
137void mrb_irep_incref(mrb_state *, struct mrb_irep *);
138void mrb_irep_decref(mrb_state *, struct mrb_irep *);
139void mrb_irep_cutref(mrb_state *, struct mrb_irep *);
140
142
143#endif /* MRUBY_IREP_H */
mruby Symbol.
mruby common platform definition"
#define MRB_END_DECL
End declarations in C mode.
Definition common.h:28
#define MRB_BEGIN_DECL
Start declarations in C mode.
Definition common.h:26
#define MRB_API
Declare a public mruby API function.
Definition common.h:108
mruby parser
irep_pool_type
Compiled mruby scripts.
Definition irep.h:18
mrb_value mrb_load_irep(mrb_state *, const uint8_t *)
load mruby bytecode functions
Definition load.c:789
uint8_t mrb_code
mruby C API entry point
Definition mruby.h:148
Definition irep.h:126
Definition irep.h:47
Definition debug.h:42
Definition irep.h:30
Definition irep.h:55
Definition mruby.h:280
Definition boxing_nan.h:40